#include <algorithm>
#include <boost/lambda/lambda.hpp>
#include <boost/regex.hpp>
#include <boost/version.hpp>
#include <iostream>
#include <iterator>
#include <string>

using namespace std;
using namespace boost::lambda;
typedef std::istream_iterator<int> in;

void DisplayUsage(const std::string& binary) {
  std::cout
      << "usage: " << binary << " <command> [<args>]\n"
      << "The " << binary << " commands are:\n"
      << "\tBoostTutorial\tArgv1\n"
      << "\tArgv1\tThe 1st parameter is in [1,2,3] means the number of tutorial\n"
      << std::endl;
}

std::string GetFileName(const std::string &path) {
  std::string::size_type start = path.rfind('/');
  if (start == std::string::npos) {
    start = 0;
  } else {
    // Move to the next char after '/'.
    ++start;
  }
  return path.substr(start, std::string::npos);
}


int main(int argc, char* argv[]) {
  std::string binary = GetFileName(std::string(argv[0]));
  if (argc != 2) {
    DisplayUsage(binary);
    return -1;
  }

  if (*argv[1] == '1') {
    cout << "Boost 【1】 version" << endl;
    cout << "Hello, World!" << endl;
    cout << "Boost版本：" << BOOST_VERSION << "" << endl;
  } else if (*argv[1] == '2') {
    cout << "Boost 【2】reg" << endl;
    std::string line;
    boost::regex pat("^Subject: (Re: |Aw: )*(.*)");
    while (std::cin) {
      std::getline(std::cin, line);
      boost::smatch matches;
      if (boost::regex_match(line, matches, pat))
        std::cout << matches[2] << std::endl;
    }
  } else if (*argv[1] == '3') {
    cout << "Boost 【3】 lambda" << endl;
    std::for_each(in(std::cin), in(), std::cout << (_1 * 3) << " ");
  } else {
    std::cout << "no more tutorials!" << std::endl;
  }
}